package com.example.demo.customer;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
@Entity
@Table
public class Customer {
        @Id
        private Long id;
        @NotBlank
        private String name;

        @NotBlank
        @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)      //给pwd字段加上注解：只允许写入
        private String password;

        @NotBlank
        @Email
        private String email;

        public Customer(){

        }

        public Customer(Long id, String name, String password, String email) {
            this.id = id;
            this.name = name;
            this.password = password;
//            添加新的私有变量password时，记得括号中的变量定义也需要同步补充   :String password
            this.email = email;
        }

//      注解@JsonProperty:指定返回的json中，属性的名字（括号中自定义内容-->"xxx"）
        @JsonProperty("customerId")
        public Long getId() {
            return id;
        }

//        public long getCustomerID(){
//            return id;
//        }

    public String getEmail() {
        return email;
    }

    public String getName() {
            return name;
        }

        @JsonIgnore     //  注解@JsonIgnore：可以不返回属性到客户端
//        生成新的私有变量password，相应的Getter方法
       public String getPassword(){
            return password;
       }

    @Override
    public String toString() {
        return "Customer{" +
                "id=" + id +
                ", name='" + name + '\''+
                ",password='" +password+'\'' +
                '}';
    }
}

